package client.messages;

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;

import data.Invite;
import data.room.Reservation;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;

import miscellaneous.TimeSupport;

public class InviteCard extends JPanel{
	private JLabel startAndTimeLabel;
	private JLabel meetingLeaderLabel;
	private JLabel title;
	private JTextArea description;
	private JLabel startAndTime;
	private JLabel meetingLeader;
	private String startAndTimeText;
	private Reservation reservation;
	private Invite invite;
	
	public InviteCard(Invite i) {
		invite = i;
		reservation = invite.getMeeting().getReservation();
		startAndTimeText = TimeSupport.showTimeNice(reservation.getStartTime()) + " - " + TimeSupport.showTimeNice(reservation.getEndTime());
		startAndTimeText += "  " + TimeSupport.showDateNice(reservation.getStartTime());
		
		startAndTimeLabel = new JLabel("Tidspunkt:");
		meetingLeaderLabel = new JLabel("Leder: ");
		title = new JLabel(invite.getMeeting().getTitle());
		startAndTime = new JLabel(startAndTimeText);
		meetingLeader = new JLabel(invite.getMeeting().getOwner().getName());
		
		JScrollPane scrollPane = new JScrollPane();
		description = new JTextArea(invite.getMeeting().getDescription());
		scrollPane.setViewportView(description);
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(10)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(startAndTimeLabel, GroupLayout.PREFERRED_SIZE, 72, GroupLayout.PREFERRED_SIZE)
							.addGap(4)
							.addComponent(startAndTime, GroupLayout.PREFERRED_SIZE, 145, GroupLayout.PREFERRED_SIZE))
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(meetingLeaderLabel, GroupLayout.PREFERRED_SIZE, 46, GroupLayout.PREFERRED_SIZE)
							.addGap(37)
							.addComponent(meetingLeader, GroupLayout.PREFERRED_SIZE, 138, GroupLayout.PREFERRED_SIZE))
						.addComponent(title, GroupLayout.PREFERRED_SIZE, 291, GroupLayout.PREFERRED_SIZE)
						.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 234, GroupLayout.PREFERRED_SIZE)))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(11)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(startAndTimeLabel)
						.addComponent(startAndTime))
					.addGap(1)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(meetingLeaderLabel)
						.addComponent(meetingLeader))
					.addGap(6)
					.addComponent(title)
					.addGap(6)
					.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE))
		);
		setLayout(groupLayout);
	}

	public Invite getInvite() {
		return invite;
	}
}
